import java.sql.*;
import java.util.Scanner;

public class Test3 {
    private static String driver="com.mysql.jdbc.Driver";
    private static String url="jdbc:mysql://localhost:3306/school?useSSL=false";
    private static String user="root";
    private static String password="123456";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName(driver);
        Connection conn= DriverManager.getConnection(url,user,password);
        String sql="update stu set age=? where age=?";

        Scanner sc=new Scanner(System.in);
        System.out.println("请输入您要更改的年龄值：");
        int age1= sc.nextInt();
        System.out.println("请输入您要把年龄更改到几岁");
        int age2=sc.nextInt();

        PreparedStatement pstmt= conn.prepareStatement(sql);
        pstmt.setInt(2,age1);
        pstmt.setInt(1,age2);
        int n=pstmt.executeUpdate();
        System.out.println("这个操作影响到"+n+"条记录");

        sc.close();
        pstmt.close();
        conn.close();
    }
}
